//package com.yuntsg.paperana.utils.esutils.china;
//
//import co.elastic.clients.elasticsearch.ElasticsearchClient;
//import co.elastic.clients.elasticsearch._types.query_dsl.BoolQuery;
//import co.elastic.clients.elasticsearch._types.query_dsl.FieldAndFormat;
//import co.elastic.clients.elasticsearch._types.query_dsl.MatchQuery;
//import co.elastic.clients.elasticsearch._types.query_dsl.Query;
//import co.elastic.clients.elasticsearch.core.SearchResponse;
//import co.elastic.clients.elasticsearch.core.search.Hit;
//import entity.databse_search.com.yuntsg.ruiijn.FileDetailsTxt;
//import service.paperana.com.yuntsg.ruiijn.MatchService;
//import esutils.utils.paperana.com.yuntsg.ruiijn.EsServerEntity;
//import esutils.utils.paperana.com.yuntsg.ruiijn.IndexConfig;
//import common.extractText.Tools;
//import lombok.SneakyThrows;
//import org.apache.commons.lang3.StringUtils;
//
//import java.util.ArrayList;
//import java.util.Arrays;
//import java.util.List;
//import java.util.Map;
//
//public class 基于中文检索测试 {
//    @SneakyThrows
//    public static void main(String[] args) {
//
//        String index = IndexConfig.UNIT_INDEXTEST;
//        String SENTENS1 = "从中药新药候选处方的现状";
//        ElasticsearchClient esClient = EsClient.client();
//        List<EsServerEntity> res = new ArrayList<>();
//        String finalIndex = index;
//        BoolQuery.Builder allQueryBuilder = new BoolQuery.Builder();
//        Query query = MatchQuery.of(t -> t.field("str").query(SENTENS1).minimumShouldMatch("45%"))._toQuery();
//        allQueryBuilder.must(query);
//        SearchResponse<EsServerEntity> response = esClient.search(s -> s
//                        .index(finalIndex)
//                        .fields(Arrays.asList(
//                                FieldAndFormat.of(builder -> builder.field("file_id")),
//                                FieldAndFormat.of(builder -> builder.field("sentence")),
//                                FieldAndFormat.of(builder -> builder.field("database_type")),
//                                FieldAndFormat.of(builder -> builder.field("str")),
//                                FieldAndFormat.of(builder -> builder.field("sub_project")),
//                                FieldAndFormat.of(builder -> builder.field("table_id"))))
//                        .from(0)
//                        .size(10)
//                        .highlight(h -> h.preTags("<span style=\"color:red\">").postTags("</span>").fields("str", highlightFieldBuilder -> highlightFieldBuilder))
//                        .query(allQueryBuilder.build()._toQuery()),
//                EsServerEntity.class
//        );
//        List<Hit<EsServerEntity>> hits = response.hits().hits();
//        for (Hit<EsServerEntity> hit : hits) {
//            EsServerEntity source = hit.source();
//            Map<String, List<String>> highlight = hit.highlight();
//            StringBuffer news = new StringBuffer();
//            highlight.forEach((k, v) -> {
//                for (String s : v) {
//                    news.append(s+" ");
//                }
//            });
//            source.setESid(hit.id());
//            source.setStrMatchRed(news.toString());
//            res.add(source);
//        }
//
//        System.out.println(res);
//
//    }
//
//}
